package br.com.rafael.gestorinvestimentos.DAO;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.rafael.gestorinvestimentos.util.HibernateUtil;

public class DAOFactory {
	private final Session session;
	private Transaction transaction;
	
	public DAOFactory(){
		session = HibernateUtil.getSession();
	}
	
	public void beginTransaction() {
		this.transaction = this.session.beginTransaction();
	}
	
	public void commit() {
		this.transaction.commit();
		this.transaction = null;
	}
	
	public boolean hasTransaction() {
		return this.transaction != null;
	}
	
	public void rollback() {
		this.transaction.rollback();
		this.transaction = null;
	}
	
	public void closeSession() {
		this.session.close();
	}
	
	public void refreshObject(Object object){
		this.session.refresh(object);
	}
	
	public PortfolioDAO getPortfolioDAO(){
		return new PortfolioDAO(this.session);
	}
	
	public ComposicaoDAO getComposicaoDAO(){
		return new ComposicaoDAO(this.session);
	}
	
	public ItemPortfolioDAO getItemPortfolioDAO(){
		return new ItemPortfolioDAO(this.session);
	}

	public OperacaoDAO getOperacaoDAO(){
		return new OperacaoDAO(this.session);
	}

	public NegocioDAO getNegocioDAO(){
		return new NegocioDAO(this.session);
	}

	public BalancoDAO getBalancoDAO(){
		return new BalancoDAO(this.session);
	}

	public LancamentoDAO getLancamentoDAO(){
		return new LancamentoDAO(this.session);
	}

	public AcaoDAO getAcaoDAO(){
		return new AcaoDAO(this.session);
	}
	
	public OpcaoDAO getOpcaoDAO(){
		return new OpcaoDAO(this.session);
	}

	public TermoDAO getTermoDAO(){
		return new TermoDAO(this.session);
	}

	public AtivoFinanceiroDAO getAtivoFinanceiroDAO(){
		return new AtivoFinanceiroDAO(this.session);
	}
}
